package com.tgra;

import java.nio.FloatBuffer;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.BufferUtils;

public class Pyramid {

	FloatBuffer vertexBuffer;
	FloatBuffer texCoordBuffer;
	
	Texture tex;
	
	float height = (float)Math.sin(Math.PI/3.0f);
	
	public Pyramid(String textureImage)
	{		
		vertexBuffer = BufferUtils.newFloatBuffer(36);
		vertexBuffer.put(new float[] {0.0f, height/2.0f, 0.0f, -0.5f, -height/2.0f, -0.5f,
									  -0.5f, -height/2.0f, 0.5f, 
									  0.0f, height/2.0f, 0.0f, -0.5f, -height/2.0f, 0.5f, 
									  0.5f, -height/2.0f, 0.5f,
									   0.0f, height/2.0f, 0.0f, 0.5f, -height/2.0f, 0.5f,
									   0.5f, -height/2.0f, -0.5f, 
									   0.0f, height/2.0f, 0.0f, 0.5f, -height/2.0f, -0.5f, 
									   -0.5f, -height/2.0f, -0.5f});
		vertexBuffer.rewind();
		
		texCoordBuffer = BufferUtils.newFloatBuffer(24);
		texCoordBuffer.put(new float[] {0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
										0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
										0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
										0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f});
		texCoordBuffer.rewind();
		
		tex = new Texture(Gdx.files.internal("assets/textures/" + textureImage));
	}
	

	public void draw()
	{
		Gdx.gl11.glShadeModel(GL11.GL_SMOOTH);
		Gdx.gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, vertexBuffer);
		
		Gdx.gl11.glEnable(GL11.GL_TEXTURE_2D);
		Gdx.gl11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
		
		tex.bind();  //Gdx.gl11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

		Gdx.gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, texCoordBuffer);

		Gdx.gl11.glNormal3f(-0.5f, height, 0.0f);
		Gdx.gl11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 3);
		Gdx.gl11.glNormal3f(0.0f, height, 0.5f);
		Gdx.gl11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 3, 3);
		Gdx.gl11.glNormal3f(0.5f, height, 0.0f);
		Gdx.gl11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 6, 3);
		Gdx.gl11.glNormal3f(0.0f, height, -0.5f);
		Gdx.gl11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 9, 3);

		Gdx.gl11.glDisable(GL11.GL_TEXTURE_2D);
		Gdx.gl11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
		
	}
}